package com.hrbxlh.util;

import com.github.pagehelper.PageInfo;
import com.google.common.base.MoreObjects;

import java.util.List;

/**
 * 分页
 *
 * @author cheer
 */
public class Page<T> {

    private Integer pageNum;

    private Integer pageSize;

    private Integer pages;

    private Integer total;

    private List<T> list;

    public static <T> Page<T> create(PageInfo pageInfo, List<T> data) {
        Page<T> page = new Page<>();
        page.setPageNum(pageInfo.getPageNum());
        page.setPageSize(pageInfo.getPageSize());
        page.setPages(pageInfo.getPages());
        page.setList(data);
        page.setTotal((int) pageInfo.getTotal());
        return page;
    }

    public Integer getPageNum() {
        return pageNum;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getPages() {
        return pages;
    }

    public void setPages(Integer pages) {
        this.pages = pages;
    }

    public Integer getTotal() {
        return total;
    }

    public void setTotal(Integer total) {
        this.total = total;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this)
                .add("pageNum", pageNum)
                .add("pageSize", pageSize)
                .add("pages", pages)
                .add("list", list)
                .toString();
    }
}
